package com.leyou.auth.web;

import com.leyou.auth.service.UserAuuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequestMapping("/user")
@RestController
public class UserAuthController {

    @Autowired
    private UserAuuthService userAuuthService;


    @PostMapping("/login")
    public ResponseEntity<Void> login(
            @RequestParam("username") String username,
            @RequestParam("password") String password,
            HttpServletResponse response) {
        this.userAuuthService.login(username,password,response);
        return ResponseEntity.ok().build();
    }
    @PostMapping("/logout")
    public ResponseEntity<Void> logot(HttpServletRequest request, HttpServletResponse response){
        this.userAuuthService.logout(response,request);
        return ResponseEntity.ok().build();
    }
}

